package com.ruoyi.teaching.controller;

import java.util.List;
import java.io.IOException;

import com.ruoyi.teaching.dto.vo.YaCourseDesignVO;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.teaching.domain.YaCourseDesign;
import com.ruoyi.teaching.service.IYaCourseDesignService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 课程设计Controller
 *
 * @author ruoyi
 * @date 2025-09-11
 */
@RestController
@RequestMapping("/course_design")
public class YaCourseDesignController extends BaseController {
  @Autowired
  private IYaCourseDesignService yaCourseDesignService;

  /**
   * 查询课程设计列表
   */
  @RequiresPermissions("teaching:course_design:list")
  @GetMapping("/list")
  public TableDataInfo list(YaCourseDesign yaCourseDesign) {
    startPage();
    List<YaCourseDesign> list = yaCourseDesignService.selectYaCourseDesignList(yaCourseDesign);
    return getDataTable(list);
  }

  /**
   * 导出课程设计列表
   */
  @RequiresPermissions("teaching:course_design:export")
  @Log(title = "课程设计", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, YaCourseDesign yaCourseDesign) {
    List<YaCourseDesign> list = yaCourseDesignService.selectYaCourseDesignList(yaCourseDesign);
    ExcelUtil<YaCourseDesign> util = new ExcelUtil<YaCourseDesign>(YaCourseDesign.class);
    util.exportExcel(response, list, "课程设计数据");
  }

  /**
   * 获取课程设计详细信息
   */
  @RequiresPermissions("teaching:course_design:query")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return success(yaCourseDesignService.selectYaCourseDesignById(id));
  }

  /**
   * 根据阶段获取所有的课程
   */
  @RequiresPermissions("teaching:course_design:query")
  @GetMapping(value = "/class/{id}")
  public AjaxResult getClassInfo(@PathVariable("id") Long stage) {
    return success(yaCourseDesignService.selectYaCourseDesignByStageId(stage));
  }

  /**
   * 新增课程设计
   */
  @RequiresPermissions("teaching:course_design:add")
  @Log(title = "课程设计", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody YaCourseDesign yaCourseDesign) {
    return toAjax(yaCourseDesignService.insertYaCourseDesign(yaCourseDesign));
  }

  /**
   * 修改课程设计
   */
  @RequiresPermissions("teaching:course_design:edit")
  @Log(title = "课程设计", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody YaCourseDesign yaCourseDesign) {
    return toAjax(yaCourseDesignService.updateYaCourseDesign(yaCourseDesign));
  }

  /**
   * 批量修改课程设计
   */
  @RequiresPermissions("teaching:course_design:edit")
  @Log(title = "课程设计", businessType = BusinessType.UPDATE)
  @PutMapping("/batch")
  public AjaxResult editBatch(@RequestBody YaCourseDesignVO yaCourseDesignVO) {
    return toAjax(yaCourseDesignService.updateYaCourseDesignBatch(yaCourseDesignVO));
  }

  /**
   * 删除课程设计
   */
  @RequiresPermissions("teaching:course_design:remove")
  @Log(title = "课程设计", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(yaCourseDesignService.deleteYaCourseDesignByIds(ids));
  }
}
